home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / do_buckey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  7.7 KB  |  330 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: do_buckey.c,v 1.1 89/03/17 08:21:03 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/do_buckey.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/do_buckey.c,v $$Revision: 1.1 $";
  12.  
  13. #include "bitmap.h"
  14. #include <stdio.h>
  15. #include <sys/signal.h>
  16. #include "defs.h"
  17. #include "font.h"
  18. #include "event.h"
  19.  
  20. /**
  21.     Check if the character is a "buckey" character, i.e. has the eighth bit
  22.     on.  If it does, it may be a function character which causes some
  23.     action.
  24.     Returns 0 if not a buckey characater or not an function character.
  25.     Returns 1 if a function character.
  26. */
  27. int
  28. do_buckey(c)
  29. register unsigned char    c;
  30. {
  31.     register WINDOW *win, *win2;
  32.     static int    *intp;
  33.     static int    windowflag = 0;    /* 1 when collecting window ID */
  34.     static int    windowsetid;    /* collected window set ID */
  35.     static int    windownum;    /* collected window number (in set) */
  36.     char        *index(), *print_flags(), *print_events(),
  37.                 *print_stack();
  38.     char        *print_ps();
  39.  
  40. #ifdef DEBUG
  41.     static char    debugflag = 0;
  42.     extern char    *debug_flags[];
  43.  
  44.     dprintf(b)(stderr, "Buckey %c\n", c & 0177);
  45.  
  46.     if( debugflag ) {
  47.         c &= 0177;
  48.         switch( debugflag ) {
  49.         case '+':    /* add debug value  */
  50.             {
  51.             char s[2];
  52.             s[0] = c;
  53.             s[1] = '\0';
  54.             if (debug && !index(debug_level, s)) {
  55.                 strcat(debug_level, s);
  56.                 fprintf(stderr,
  57.                     "Adding %s to debug list (now %s)\n",
  58.                     s, debug_level);
  59.             }
  60.             }
  61.             break;
  62.         case '-':    /* remove debug value  */
  63.             {
  64.             char *sp;
  65.             if (debug && (sp=index(debug_level, c))) {
  66.                 strcpy(sp, sp+1);
  67.                 fprintf(stderr,
  68.                     "Deleting %c to debug list (now %s)\n",
  69.                     c, debug_level);
  70.             }
  71.             }
  72.             break;
  73.         }
  74.         debugflag = 0;
  75.         return 1;
  76.     }
  77. #endif
  78.     if( windowflag ) {
  79.         int    i = c & 0177;
  80.  
  81.         /*    Collect digits and create windowsetid.
  82.             If a \n arrives, place window on top and swallow the
  83.             \n.
  84.             If any other character, place window on top and act
  85.             on the character.
  86.         */
  87.         switch( i ) {
  88.         case '0': case '1': case '2': case '3': case '4':
  89.         case '5': case '6': case '7': case '8': case '9':
  90.             *intp = (*intp)*10 + (i - '0');
  91.             return 1;
  92.         case ',':
  93.             windownum = 0;
  94.             intp = &windownum;
  95.             return 1;
  96.         case '\r':
  97.         case '\n':
  98.             windowflag = 0;
  99.             topwin( windowsetid, windownum );
  100.             return 1;
  101.         default:
  102.             windowflag = 0;
  103.             topwin( windowsetid, windownum );
  104.         }
  105.     }
  106.     if( !(c & 0200) )
  107.         return 0;    /* Not a buckey character. */
  108.  
  109.     c &= 0177;
  110.     switch(c) {
  111.     case 'w':    /* switch to the following window number */
  112.         windowflag = 1;
  113.         windowsetid = 0;
  114.         intp = &windowsetid;
  115.         windownum = -1;
  116.         break;
  117.             /* Single digit windowsetid numbers.  As a convenience,
  118.             '0' is mapped to window set ID 10. */
  119.     case '0': case '1': case '2': case '3': case '4':
  120.     case '5': case '6': case '7': case '8': case '9':
  121.         windowsetid = (int)(c - '0');
  122.         if( windowsetid == 0 )
  123.             windowsetid = 10;
  124.         topwin( windowsetid, -1 );
  125.         break;
  126.     case 'h':    /* hide top window on bottom */
  127.         if (active && ACTIVE(next)) {
  128.             MOUSE_OFF(mousex,mousey);
  129.             cursor_off();
  130.             ACTIVE_OFF();
  131.             hide_win();
  132.             ACTIVE_ON();
  133.             cursor_on();
  134.             MOUSE_ON(mousex,mousey);
  135.         }
  136.         break;
  137.     case ' ':                /* go to next window */
  138.         if (active && ACTIVE(next))
  139.             do_it(ACTIVE(next));
  140.         break;
  141.     case '\b':            /* move bottom window to top */
  142.         if (active && ACTIVE(next))
  143.             do_it(ACTIVE(prev));
  144.         break;
  145.     case 'l':                /* clear the window */
  146.         MOUSE_OFF(mousex,mousey);
  147.         cursor_off();
  148.         ACTIVE_OFF();
  149.         CLEAR( ACTIVE(window), ACTIVE(background) );
  150.         ACTIVE_ON();
  151.         cursor_on();
  152.         MOUSE_ON(mousex,mousey);
  153.         break;
  154.     case 'R':    /* redraw the screen */
  155.     case 'r':
  156.         MOUSE_OFF(mousex,mousey);
  157.         if( active ) {
  158.             cursor_off();
  159.             ACTIVE_OFF();
  160.         }
  161.         redraw();
  162.         if( active ) {
  163.             ACTIVE_ON();
  164.             cursor_on();
  165.         }
  166.         MOUSE_ON(mousex,mousey);
  167.         break;
  168.     case 'n':    /* make a new window 80x24 characters */
  169.     case 'N':    /* make a new window, sweept out by the mouse */
  170.         MOUSE_OFF(mousex,mousey);
  171.         if( active ) {
  172.             cursor_off();
  173.             ACTIVE_OFF();
  174.         }
  175.         if( c=='n' )
  176.             initwindow();    /* default window */
  177.         else
  178.             new_window();    /* swept out with mouse */
  179.         if( active ) {
  180.             ACTIVE_ON();
  181.             cursor_on();
  182.         }
  183.         MOUSE_ON(mousex,mousey);
  184.         break;
  185.     case 'z':    /* stop process */
  186.         suspend();
  187.         break;
  188.     case 'm':    /* move text (cut and paste) */
  189.         if( !active )
  190.             break;
  191.         MOUSE_OFF(mousex,mousey);
  192.         cursor_off();
  193.         if (cut() > 0)
  194.             paste();
  195.         cursor_on();
  196.         MOUSE_ON(mousex,mousey);
  197.         break;
  198.     case 'c':    /* start a cut of text */
  199.         if( !active )
  200.             break;
  201.         MOUSE_OFF(mousex,mousey);
  202.         cursor_off();
  203.         cut();
  204.         cursor_on();
  205.         MOUSE_ON(mousex,mousey);
  206.         break;
  207.     case 'p':    /* paste text at current cursor */
  208.         if( !active )
  209.             break;
  210.         paste();
  211.         break;
  212. #ifdef DEBUG
  213.     case '+':    /* add debug value  */
  214.     case '-':    /* remove debug value  */
  215.         debugflag = c;
  216.         break;
  217.     case '#':    /* temporary (die) abruptly */
  218.         setreuid(getuid(),getuid());
  219.         setregid(getgid(),getgid());    /* so we can get a core dump */
  220.         kill(getpid(),SIGQUIT);
  221.         sleep(1);
  222.         break;
  223.     case '?':                /* Print debugging flags */
  224.         if( !debug )
  225.            break;
  226.         {
  227.             int    i;
  228.  
  229.             fprintf(stderr,"Debug flags:\r\n");
  230.             for(i=0;debug_flags[i];i++)
  231.                 fprintf(stderr,"  %s\n",debug_flags[i]);
  232.         }
  233.         break;
  234. #endif
  235.     case 'Q':    /* Quit nicely */
  236.         _quit();
  237.         exit(0);
  238.         break;
  239.     case 'I':    /* temporary (status + process info) */
  240.         if( !debug )
  241.            break;
  242.         fprintf(stderr,"please wait...\r\n");
  243.         get_ps();
  244.         /* no break */
  245.     case 'i':    /* temporary (status info) */
  246.         if( !debug )
  247.            break;
  248.         for(win=active;win!=(WINDOW *) 0;win=win->next) {
  249.             fprintf(stderr,"%s: %d,%d  %d,%d num(%d) {%s}\r\n",
  250.                 W(tty),W(x0),W(y0),
  251.                 BIT_WIDE(W(window)),BIT_HIGH(W(window)),W(num),
  252.                 c=='I' ? print_ps(W(tty)):"");
  253.             fprintf(stderr,"  flags: %s\n",print_flags(W(flags)));
  254.             fprintf(stderr,"  events: %s\n",print_events(W(event_mask)));
  255.             fprintf(stderr,"  cursors: %d,%d  %d,%d  function %d\r\n",
  256.                 W(x),W(y),W(gx),W(gy),W(op));
  257.             fprintf(stderr,"  fd's: %d,<->%d, pid(%d)",W(from_fd),
  258.                 W(to_fd),W(pid));
  259.             if (W(main)&& strcmp(W(tty),W(main)->tty)!=0)
  260.                 fprintf(stderr," main(%s)",W(main)->tty);
  261.             if W(alt)
  262.                 fprintf(stderr," alt(%s)",W(alt)->tty);
  263.             fprintf(stderr,"\r\n");
  264.             if (W(snarf))
  265.                 fprintf(stderr,"  snarf (%d) [%.30s...]\r\n",strlen(W(snarf)),
  266.                     W(snarf));
  267.             if (W(stack)) {
  268.                 fprintf(stderr,"  stacks:\r\n");
  269.                 for(win2=W(stack);win2;win2=win2->stack)
  270.                     fprintf(stderr,"\t%0x%x, events: 0x%x\r\n",
  271.                         win2->code,win2->event_mask);
  272.             }
  273.         }
  274.         if (c=='I')
  275.             free_ps();
  276.         break;
  277. #ifdef MALLOC
  278.     case 'M':    /* temporary (malloc info) */
  279.         mstats("for MGR");
  280.         break;
  281. #endif
  282.     default:
  283.         return 0;    /* not a valid function character */
  284.     }
  285.     return 1;        /* we acted on a function character */
  286. }
  287.  
  288.  
  289. /*    Given a WINDOW pointer, move that window to top.
  290. */
  291. static
  292. do_it(win)
  293. register WINDOW *win;
  294. {
  295.     MOUSE_OFF(mousex,mousey);
  296.     cursor_off();
  297.     ACTIVE_OFF();
  298.     expose(win);
  299.     ACTIVE(flags) &= ~W_NOINPUT;
  300.     ACTIVE_ON();
  301.     cursor_on();
  302.     MOUSE_ON(mousex,mousey);
  303. }
  304.  
  305.  
  306. /*    Given a window set ID and window number, move the window with
  307.     that ID and number to the top.
  308.     If the window number is -1, it is not considered and bottom-most
  309.     window from the set is moved to the top.
  310. */
  311. topwin( winsetid, winnum )
  312. register int    winsetid,
  313.         winnum;
  314. {
  315.     register WINDOW    *win;
  316.  
  317.     if( !active  ||  !ACTIVE(next) )
  318.         return;
  319.     /*    We look from the back of the list toward the front so that
  320.         we can cycle through a set.
  321.     */
  322.     for( win = ACTIVE(prev);  win != active;  win = win->prev ) {
  323.         if( winsetid  == W(setid)  &&
  324.             ( winnum == -1  ||  winnum == W(num) ) ) {
  325.             do_it(win);
  326.             return;
  327.         }
  328.     }
  329. }
  330.